// pages/travel/travel.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    defaultImageUrl: 'https://yueqian-1311524869.cos.ap-chengdu.myqcloud.com/images/5.png',
    messages: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this
    // 获取页面可用区域宽高
    this.setData({
      windowHeight: wx.getStorageSync('windowHeight'),
      windowWidth: wx.getStorageSync('windowWidth')
    })
    // 保持搜索框与胶囊平齐
    var menuResponse = wx.getMenuButtonBoundingClientRect()
    let capsuleHeight = menuResponse.height
    let capsuleTop = menuResponse.top
    let searchTop = capsuleTop - (34 / 2 - capsuleHeight / 2)
    this.setData({
      searchTop: searchTop
    })
    // 渲染数据后，统一清除用到的本地存储


  },
  goToDetail(event) {
    // console.log(event.currentTarget.dataset)
    wx.navigateTo({
      url: '/pages/travel/detail/detail?detailData=' + encodeURIComponent(JSON.stringify(event.currentTarget.dataset.detaildata)),
    })
  },
  goToEdit() {
    wx.navigateTo({
      url: '/pages/travel/edit/edit',
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

    var that = this

    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1
      })
    }

    //
    //获取后台数据
    wx.request({
      url: 'http://localhost:8089/travel/getTravel',
      success(res) {
        // console.log(res)
        that.setData({
          messages: res.data
        })
      }
    })
  }

})